<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
    session_start();
    include("top.php");
?>
<table width="766" height="438" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="209" height="438" valign="top" bgcolor="#F5F5F5"><?php include("left.php");?></td>
    <td width="557" align="center" valign="top" bgcolor="#FFFFFF"><table width="550" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="50">&nbsp;</td>
      </tr>
    </table>
      <table width="550" height="10" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td></td>
        </tr>
      </table>
      <table width="550" height="70" border="0" align="center" cellpadding="0" cellspacing="0">
        <?php
        /**
         * @todo 增加分页功能
         */
//                 $sql= exectue_sql_statement($conn, "select top 4 Book.book_id, book_name, book_introduction, unit_price, book_img, book_amount from Book, Store where Book.book_id=Store.book_id order by Book.book_id desc");
//		 $info=sqlsrv_fetch_array($sql);
                 $sql = exectue_sql_statement($conn, "select count(*) as total from Book");
                 $info = sqlsrv_fetch_array($sql);
                 $total = $info['total'];
		 if($total==0){//if($info==false)
		   echo "本站暂无最新图书!";
		  } 
		 else{ 
                   $pagesize=3;
		   if ($total<=$pagesize){
		      $pagecount=1;
			} 
			if(($total%$pagesize)!=0){
			   $pagecount=intval($total/$pagesize)+1;
			
			}else{
			   $pagecount=$total/$pagesize;
			
			}
			if((@$_GET['page'])==""){//实在不知道怎么去掉那个可恶的Notice了
			    $page=1;
			
			}else{
			    $page=intval($_GET['page']);
			
			}
                    $sql= exectue_sql_statement($conn, "select top $pagesize ".
                                                       "Book.book_id, book_name, book_introduction, unit_price, book_img, book_amount ".
                                                       "from Book, Store ".
                                                       "where Book.book_id not in ".
                                                       "(select top ".($page-1)*$pagesize." Book.book_id from Book order by Book.book_id desc) ".
                                                       "and Book.book_id=Store.book_id ".
                                                       "order by Book.book_id desc");
                    $info=sqlsrv_fetch_array($sql);
		    do{ 
	   ?>
          <table>
        <tr>
          <td width="89"  rowspan="6"><div align="center">
              <?php
			 if($info['book_img']==""){
			   echo "暂无图片!";
			 }
			 else{
			?>
              <a href="bookinfo.php?book_id=<?php echo $info['book_id'];?>"><img border="0" src="<?php echo $info['book_img'];?>" width="80" height="80"></a>
              <?php
			 }
			?>
          </div></td>
          <td width="92" height="20" align="left" bgcolor="#FFFFFF"><div align="center">图书名称：</div></td>
                  <td width="134" bgcolor="#FFFFFF"><div align="left">&nbsp;<?php echo $info['book_name'];?></div></td>
        </tr>
        <tr>
          <td height="20" align="left" bgcolor="#FFFFFF"><div align="center">售价：</div></td>
          <td width="134" bgcolor="#FFFFFF"><div align="left">&nbsp;<?php echo $info['unit_price'];?></div></td>
        </tr>
        <tr>
           <td width="100" bgcolor="#FFFFFF"><div align="center">数量：</div></td>
           <td width="129" bgcolor="#FFFFFF"><div align="left">&nbsp;<?php echo $info['book_amount'];?></div></td>
        </tr>
        <tr>
          <td><div align="center"><a href="addtocart.php?book_id=<?php echo $info['book_id'];?>"><input type="button" value="放入购物车"></a>&nbsp;&nbsp;</div></td>
        </tr>
        </table>
        <!--
        <tr>
          <td width="93" height="20"><div align="center" style="color: #000000">商品简介：</div></td>
          <td height="20" colspan="5"><div align="left"><?php echo $info[jianjie];?></div></td>
        </tr>
        -->
        <?php
	    	}while($info=sqlsrv_fetch_array($sql));
		 }
		?>
      <table width="600" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="165">
    </td>
    <td width="585"><div align="right">&nbsp;共有图书
        <?php
		   echo $total;
		  ?>
        &nbsp;本&nbsp;每页显示&nbsp;<?php echo $pagesize;?>&nbsp;本&nbsp;第&nbsp;<?php echo $page;?>&nbsp;页/共&nbsp;<?php echo $pagecount; ?>&nbsp;页
        <?php
		  if($page>=2)
		  {
		  ?>
        <a href="shownewbook.php?page=1" title="首页"><font face="webdings"> 9 </font></a> <a href="shownewbook.php?id=<?php echo $id;?>&page=<?php echo $page-1;?>" title="前一页"><font face="webdings"> 7 </font></a>
        <?php
		  }
		   if($pagecount<=4){
		    for($i=1;$i<=$pagecount;$i++){
		  ?>
        <a href="shownewbook.php?page=<?php echo $i;?>"><?php echo $i;?></a>
        <?php
		     }
		   }else{
		   for($i=1;$i<=4;$i++){	 
		  ?>
        <a href="shownewbook.php?page=<?php echo $i;?>"><?php echo $i;?></a>
        <?php }?>
        <a href="shownewbook.php?page=<?php echo $page-1;?>" title="后一页"><font face="webdings"> 8 </font></a> <a href="shownewbook.php?id=<?php echo $id;?>&page=<?php echo $pagecount;?>" title="尾页"><font face="webdings"> : </font></a>
        <?php }?>
    </div></td>
  </tr>
</table>
      </table>
<?php
 include("bottom.php");
?>